package org.apache.harmony.javax.security.sasl;

import java.security.Provider;
import java.security.Security;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import org.apache.harmony.javax.security.auth.callback.CallbackHandler;

public class Sasl
{
  private static final String CLIENTFACTORYSRV = "SaslClientFactory";
  private static final String SERVERFACTORYSRV = "SaslServerFactory";
  public static final String POLICY_NOPLAINTEXT = "javax.security.sasl.policy.noplaintext";
  public static final String POLICY_NOACTIVE = "javax.security.sasl.policy.noactive";
  public static final String POLICY_NODICTIONARY = "javax.security.sasl.policy.nodictionary";
  public static final String POLICY_NOANONYMOUS = "javax.security.sasl.policy.noanonymous";
  public static final String POLICY_FORWARD_SECRECY = "javax.security.sasl.policy.forward";
  public static final String POLICY_PASS_CREDENTIALS = "javax.security.sasl.policy.credentials";
  public static final String MAX_BUFFER = "javax.security.sasl.maxbuffer";
  public static final String RAW_SEND_SIZE = "javax.security.sasl.rawsendsize";
  public static final String REUSE = "javax.security.sasl.reuse";
  public static final String QOP = "javax.security.sasl.qop";
  public static final String STRENGTH = "javax.security.sasl.strength";
  public static final String SERVER_AUTH = "javax.security.sasl.server.authentication";

  private static Object newInstance(String paramString, Provider paramProvider)
    throws SaslException
  {
    String str = "auth.31";
    ClassLoader localClassLoader = paramProvider.getClass().getClassLoader();
    if (localClassLoader == null)
      localClassLoader = ClassLoader.getSystemClassLoader();
    try
    {
      Object localObject = Class.forName(paramString, true, localClassLoader).newInstance();
      return localObject;
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
      throw new SaslException(str + paramString, localIllegalAccessException);
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new SaslException(str + paramString, localClassNotFoundException);
    }
    catch (InstantiationException localInstantiationException)
    {
      throw new SaslException(str + paramString, localInstantiationException);
    }
  }

  private static Collection<?> findFactories(String paramString)
  {
    HashSet localHashSet1 = new HashSet();
    Provider[] arrayOfProvider = Security.getProviders();
    if ((arrayOfProvider == null) || (arrayOfProvider.length == 0))
      return localHashSet1;
    HashSet localHashSet2 = new HashSet();
    for (int i = 0; i < arrayOfProvider.length; i++)
    {
      String str1 = arrayOfProvider[i].getName();
      Enumeration localEnumeration = arrayOfProvider[i].keys();
      while (localEnumeration.hasMoreElements())
      {
        String str2 = (String)localEnumeration.nextElement();
        if (str2.startsWith(paramString))
        {
          String str3 = arrayOfProvider[i].getProperty(str2);
          try
          {
            if (localHashSet2.add(str1.concat(str3)))
              localHashSet1.add(newInstance(str3, arrayOfProvider[i]));
          }
          catch (SaslException localSaslException)
          {
            localSaslException.printStackTrace();
          }
        }
      }
    }
    return localHashSet1;
  }

  public static Enumeration<SaslClientFactory> getSaslClientFactories()
  {
    Collection localCollection = findFactories("SaslClientFactory");
    return Collections.enumeration(localCollection);
  }

  public static Enumeration<SaslServerFactory> getSaslServerFactories()
  {
    Collection localCollection = findFactories("SaslServerFactory");
    return Collections.enumeration(localCollection);
  }

  public static SaslServer createSaslServer(String paramString1, String paramString2, String paramString3, Map<String, ?> paramMap, CallbackHandler paramCallbackHandler)
    throws SaslException
  {
    if (paramString1 == null)
      throw new NullPointerException("auth.32");
    Collection localCollection = findFactories("SaslServerFactory");
    if (localCollection.isEmpty())
      return null;
    Iterator localIterator = localCollection.iterator();
    while (localIterator.hasNext())
    {
      SaslServerFactory localSaslServerFactory = (SaslServerFactory)localIterator.next();
      String[] arrayOfString = localSaslServerFactory.getMechanismNames(null);
      int i = 0;
      if (arrayOfString != null)
        for (int j = 0; j < arrayOfString.length; j++)
          if (arrayOfString[j].equals(paramString1))
          {
            i = 1;
            break;
          }
      if (i != 0)
      {
        SaslServer localSaslServer = localSaslServerFactory.createSaslServer(paramString1, paramString2, paramString3, paramMap, paramCallbackHandler);
        if (localSaslServer != null)
          return localSaslServer;
      }
    }
    return null;
  }

  public static SaslClient createSaslClient(String[] paramArrayOfString, String paramString1, String paramString2, String paramString3, Map<String, ?> paramMap, CallbackHandler paramCallbackHandler)
    throws SaslException
  {
    if (paramArrayOfString == null)
      throw new NullPointerException("auth.33");
    Collection localCollection = findFactories("SaslClientFactory");
    if (localCollection.isEmpty())
      return null;
    Iterator localIterator = localCollection.iterator();
    while (localIterator.hasNext())
    {
      SaslClientFactory localSaslClientFactory = (SaslClientFactory)localIterator.next();
      String[] arrayOfString = localSaslClientFactory.getMechanismNames(null);
      int i = 0;
      if (arrayOfString != null)
        for (int j = 0; j < arrayOfString.length; j++)
          for (int k = 0; k < paramArrayOfString.length; k++)
            if (arrayOfString[j].equals(paramArrayOfString[k]))
            {
              i = 1;
              break;
            }
      if (i != 0)
      {
        SaslClient localSaslClient = localSaslClientFactory.createSaslClient(paramArrayOfString, paramString1, paramString2, paramString3, paramMap, paramCallbackHandler);
        if (localSaslClient != null)
          return localSaslClient;
      }
    }
    return null;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.apache.harmony.javax.security.sasl.Sasl
 * JD-Core Version:    0.6.1
 */